package com.luyuan.crm.report.delivery.internal;

import java.util.Date;
import java.util.List;

import com.luyuan.crm.report.delivery.DeliveryReport;
import com.luyuan.crm.report.delivery.DeliveryReportService;
import com.ruijie.foundation.dao.support.HibernateEntityDao;
import com.ruijie.util.DateUtils;

public class DeliveryReportServiceImpl extends HibernateEntityDao<DeliveryReport> implements DeliveryReportService {

    @SuppressWarnings("unchecked")
    @Override
    public List<DeliveryReport> findByDate(Date date) {
        return find("from DeliveryReport where deliveryDate >= ? and deliveryDate < ?", DateUtils.truncateDay(date),
                DateUtils.truncateDay(DateUtils.addDate(date, 1)));
    }

    @Override
    public void generationReport() {
        Date date = DateUtils.truncateDay(new Date());
        Date endDate = DateUtils.addDate(date, 1);
        getNamedQuery("report.deliveryReport.clearToDayReport", date, endDate).executeUpdate();
        getNamedQuery("report.deliveryReport.generationReport", date, endDate).executeUpdate();
    }

}
